home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
039a
/
d3d.zip
/
TRAFO.C
< prev
Wrap
Text File
|
1989-11-24
|
2KB
|
80 lines
/* TRAFO: Three-dimensional transformations */
#include <math.h>
double r11, r12, r13, r21, r22, r23,
r31, r32, r33, r41, r42, r43;
void initrotate( double a1, double a2, double a3,
double v1, double v2, double v3, double alpha)
/* Computation of the rotation matrix
| r11 r12 r13 0 |
| r21 r22 r23 0 |
R = | r31 r32 r33 0 |
| r41 r42 r43 1 |
to be used as [x1 y1 z1 1] = [x y z 1] R,
see function 'rotate'.
Point (x1, y1, z1) is the image of (x, y, z).
The rotation takes place about the axis
(a1, a3, a3) + lambda(v1, v2, v3)
and through the angle alpha. */
{
double rho, theta, cal, sal, cph, sph, cth, sth,
cph2, sph2, cth2, sth2, pi, cal1;
cal = cos(alpha);
sal = sin(alpha);
cal1 = 1.0 - cal;
rho = sqrt(v1*v1 + v2*v2 + v3*v3);
pi = 4.0 * atan(1.0);
if(rho == 0.0) {
theta = 0.0;
cph = 1.0;
sph = 0.0;
}
else {
if (v1 == 0.0)
theta = (v2 >= 0.0 ? 0.5*pi : 1.5 * pi);
else {
theta = atan(v2/v1);
if (v1 < 0)
theta += pi;
}
cph = v3/rho;
sph = sqrt(1.0 - cph*cph);
/* cph = cos(phi), sph = sin (phi) */
}
cth = cos(theta);
sth = sin(theta);
cph2 = cph*cph;
sph2 = 1.0 - cph2;
cth2 = cth*cth;
sth2 = 1.0 - cth2;
r11 = (cal*cph2 + sph2)*cth2 + cal*sth2;
r12 = sal*cph + cal1*sph2*cth*sth;
r13 = sph*(cph*cth*cal1 - sal*sth);
r21 = sph2*cth*sth*cal1 - sal*cph;
r22 = sth2*(cal*cph2 + sph2) + cal*cth2;
r23 = sph*(cph*sth*cal1 + sal*cth);
r31 = sph*(cph*cth*cal1 + sal*sth);
r32 = sph*(cph*sth*cal1 - sal*cth);
r32 = sph*(cph*sth*cal1 - sal*cth);
r33 = cal*sph2 + cph2;
r41 = a1- a1*r11 - a2*r21 - a3*r31;
r42 = a2- a1*r12 - a2*r22 - a3*r32;
r43 = a3- a1*r13 - a2*r23 - a3*r33;
}
void rotate(double x, double y, double z,
double *px1, double *py1, double *pz1)
{
*px1 = x*r11 + y*r21 + z*r31 + r41;
*py1 = x*r12 + y*r22 + z*r32 + r42;
*pz1 = x*r13 + y*r23 + z*r33 + r43;
}